From cd92ff492725f4b43053d48bf3e80e708335ea43 Mon Sep 17 00:00:00 2001 From: robertl Date: Tue, 13 Sep 2005 06:19:24 +0000 Subject: [PATCH] Add xstrrstr for searching strings from back. Make geo use it. --- gpsbabel/defs.h | 1 + gpsbabel/geo.c | 2 +- gpsbabel/util.c | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 32a9935ac..2dced8f30 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -593,6 +593,7 @@ int case_ignore_strncmp(const char *s1, const char *s2, int n); char *strsub(const char *s, const char *search, const char *replace); char *gstrsub(const char *s, const char *search, const char *replace); +char *xstrrstr(const char *s1, const char *s2); void rtrim(char *s); signed int get_tz_offset(void); time_t mkgmtime(struct tm *t); diff --git a/gpsbabel/geo.c b/gpsbabel/geo.c index 4ce36d04e..c1f4fc96a 100644 --- a/gpsbabel/geo.c +++ b/gpsbabel/geo.c @@ -95,7 +95,7 @@ void wpt_name(const char *args, const char **unused) wpt_tmp->description = xstrappend(wpt_tmp->description,args); if (nuke_placer) { - char *s = strstr(wpt_tmp->description, " by "); + char *s = xstrrstr(wpt_tmp->description, " by "); if (s) { *s = '\0'; } diff --git a/gpsbabel/util.c b/gpsbabel/util.c index 03bffb331..ad4edf439 100644 --- a/gpsbabel/util.c +++ b/gpsbabel/util.c @@ -727,6 +727,22 @@ gstrsub(const char *s, const char *search, const char *replace) return o; } +/* + * Like strstr, but starts from back of string. + */ +char * +xstrrstr(const char *s1, const char *s2) +{ + char *r = NULL, *next = NULL; + + while (next = strstr(s1, s2)) { + r = next; + s1 = next + 1; + } + return r; +} + + char * rot13( const char *s ) { -- 2.30.2